/**
  
 **/
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;


/**
     The  VendingMachineItemTest Class.
 **/

public class VendingMachineItemTest {
        
        /**The Coke Object **/
	
        private VendingMachineItem Coke;
        
        /** The Pepsi Object **/
        
        private VendingMachineItem Pepsi;
        
        
        /**
           The Test is Run by creating Objects.
          @throws the Exception 
          
         **/
        
        @Before
        public void setUp() throws Exception {
                Coke = new VendingMachineItem("Coke", 1.75);
                Pepsi = new VendingMachineItem("Pepsi", 1.50);
        }

        /**
         Tear down.
         @throws the Exception 
         **/
        
        @After
        public void tearDown() throws Exception {
        
        }

        /**
         Testing the vending machine item constructor for the not null objects.
         
         **/
        
        @Test
        public void testVendingMachineItem() {
                assertNotNull(Pepsi);     
        }

        /**
          Testing the vending machine item constructor with some negative price.
          Postcondition:The test run will be true when the item's price is negative value.
         @throws  if price is less than zero the VendingMachineException is thrown
         **/
        
        @Test(expected=VendingMachineException.class)
        public void VendingMachine_Negativeamount()  throws Exception{
        
                new VendingMachineItem("Snicker", -2.00);    /** The Snicker Object with negative price. */
        }
        
        /**
         Testing vending machine item constructor with some negative values to check if Price is less than zero 
           Postcondition: The test will be true if the price is a negative value.
          @throws VendingMachineException Thrown if price is less than zero
         **/
        
        @Test 
        public void testVendingMachineP_LessThanZero() throws Exception{
                
        	/** The Snicker with negative value */
                try{
                        VendingMachineItem temp = new VendingMachineItem("Snicker", -1.00);
                }
                catch(final VendingMachineException e)
                {
                        String msg = "Price is less than zero";
                        assertEquals(msg, e.getMessage());
                }
        }
        
        
        
        /**
          Test vending machine item constructor with the price  0.
          @throws VendingMachineException  if price is less than zero
         **/
        
        @Test 
        public void testVendingMachineItemp_Zero(){
                /** The Snicker wiht 0 value. */
        	
                new VendingMachineItem("Snicker", 0.00);
        }
        
        

        /**
         It will Test vending machine item constructor with a null value.
         **/
        
        @Test 
        public void testVendingMachineIName_Null() {
                new VendingMachineItem(null, 1.00);
        }
        
        /**
         Test the getName() of the vending machine item -  the actual name of the item should be matched.
         Postcondition:Return true if the string corresponding to the name of the vending machine item matches the testing result.
         **/
        
        @Test
        public void testGetName_nameCheck() {
                //Return true if the string corresponding to the name of the vending machine item matches the testing result.
                assertEquals("Coke", Coke.getName());
        }
        
        /**
         **Test the getName() method of the vending machine item for the null values.
         Postcondition: It will return False if the string corresponding to the name of the vending machine item.
         **/
        
        @Test
        public void testGetName_Checknull() {
               
                assertEquals(null, Coke.getName());
        }

        
        /**
         Test getPrice() of Vending Machine
         Postcondition: The actual price of the item should be matched
         **/
        
        @Test
        public void testGetPrice() {
                
                assertEquals(1.75, Coke.getPrice(), 0.20);
        }


        /**
         It will test the getPrice() of Vending Machine with margin
         Postcondition: It will match the actual price of the item 
         **/
        
        @Test
        public void testGetPrice_withmargin() {
                
                assertEquals(1.85, Coke.getPrice(), 0.20);
        }
        
}